/**
 * 产品分类列表
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author duanzuocai
 * @since 2018/11/17
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;

    var cols = [
        [
            {field: 'id', type: 'checkbox', fixed: 'left', width: 50, align: 'center'},
            {field: 'id', title: 'ID', width: 280, align: 'center', unresize: true, sort: false},
            {
                field: 'type', title: '类型', width: 280, align: 'center', unresize: true, templet: function (d) {
                    return zmnEnum.PERMITDATA_TYPE[d.type];
                }
            },{
            field: 'type', title: '类型数据', width: 280, align: 'center', unresize: true, templet: function (d) {
                var name = "全部";

                if (d.type == 1 && d.companyName != null) {
                    name = d.companyName;
                } else if (d.type == 8 && d.companyName != null) {
                    name = d.companyName;
                } else if (d.type == 2 && d.serviceName != null) {
                    name = d.serviceName;
                } else if (d.type == 3 && d.cityName != null) {
                    name = d.cityName;
                } else if (d.type == 4 && d.channelName != null) {
                    name = d.channelName;
                } else if ((d.type == 5 || d.type == 6) && d.typeData > 0) {
                    name = zmnEnum.PLAT_TYPE[d.typeData];
                } else if ((d.type == 7) && d.typeData > 0) {
                    name = d.companyName;
                } else if ((d.type == 9) && d.typeData > 0) {
                    name = d.companyName;
                } else if ((d.type == 10) && d.typeData > 0) {
                    name = d.countyName;
                }
                return name;
            }
        },
            {field: 'realName', title: '真实名字', width: 280, align: 'center', unresize: true},
            {field: 'creater', title: '创建人', width: 280, align: 'center', unresize: true},
            {field: 'createTime', title: '创建时间', templet: '#createTime',  align: 'center', unresize: true,
                templet :function (row){
                    return zmnUtil.createTime(row.createTime);
                }
            }
        ]
    ];

    /**
     * 表格加载方法
     * @param data
     */
    let tableRender = function (data) {
        zmnLayUtil.layTableRender(table, cols, "zmn-staffpermitdata-table", data, "/mc/staff/loadData.action",{limit:50,page:true});
    };

    /**
     * 初始化表格
     */
    tableRender({staffId:json.staffId});

    /**
     * 表单提交方法
     */
    form.on('submit(query-submit)', function (obj) {
        tableRender(obj.field);
        return false;
    });

    /**
     * 删除权限
     */
    table.on("toolbar(staffpermitdata)", function (obj) {
        if (obj.event != "del") {
            return;
        }
        var checkData = table.checkStatus('zmn-staffpermitdata-table').data;
        if (checkData.length === 0) {
            return layer.alert("请选择至少一条数据！");
        }
        var ids = new Array();
        for (var i = 0;i<checkData.length;i++){
            ids.push(checkData[i].id)
        }
        zmnPage.layStartStop(obj, "/mc/staff/deleteByIds.action", ids.join(","));
    });
    //对外暴露的接口
    exports('art_staffpermitdata_list', {});
});

function toEditPermit(){
    let staffId = json.staffId;
    layer.open({
        type: 2,
        title:'权限管理',
        area: ['90%', '80%'],
        content: '/mc/staff/data/detail.action?staffId='+staffId
    });
}